package com.zjw.designPattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * proxy:b被代理对象
 * method:被代理对象方法
 * args:参数
 * */

public class TimeHandler implements InvocationHandler {

    private Object target;

    public TimeHandler(Object target) {
        this.target = target;
    }

    /**
     * 代理对象需要处理的内容
     * */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Long start = System.currentTimeMillis();
        method.invoke(target);
        Long end = System.currentTimeMillis();
        System.out.println("汽车行驶了:"+(end - start)+"毫秒");
        return null;
    }
}
